package com.wz.kwic;

import java.io.File;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        File infile = new File("d:\\temp\\mykwic_in.txt");
        File outfile = new File("d:\\temp\\mykwic_out.txt");

        Scanner inputfile;
        Scanner outputfile;

        try {
            inputfile = new Scanner(infile);
            outputfile = new Scanner(outfile);
            // 定义三个管道
            Pipe pipe1 = new Pipe();
            Pipe pipe2 = new Pipe();
            Pipe pipe3 = new Pipe();
            // 定义四种过滤器
            Input input = new Input(infile, pipe1);
            Shift shift = new Shift(pipe1, pipe2);
            Alphabetizer alph = new Alphabetizer(pipe2, pipe3);
            Output output = new Output(pipe3, outfile);
            // 启动四种过滤器的线程
//			input.start();
//			shift.start();
//			alph.start();
//			output.start();
            //不启用线程，顺序执行四个过滤器
            input.transform();
            shift.transform();
            alph.transform();
            output.transform();
            // 直接输出结果
            System.out.println("-----  infile   -----");
            String str = null;
            while (inputfile.hasNextLine()) {
                str = inputfile.nextLine();
                System.out.println(str);
            }
            System.out.println("input  end");
            //启用线程时要让当前线程睡一段时间.
            //Thread.sleep(3000);
            System.out.println("-----  outfile  -----");
            while (outputfile.hasNextLine()) {
                str = outputfile.nextLine();
                System.out.println(str);
            }
            inputfile.close();
            outputfile.close();
        } catch (Exception e) {
            // e.getMessage();
            e.printStackTrace();
        }
    }
}